<?php
/*
Copyright 2008, Nathalia


Author:
Nathalia Sautchuk Patrício          (nathalia.sautchuk@gmail.com)

*/
class Cadastrar extends TPage
{
    public function onInit($param)
    {        
		parent::onInit($param);

        $this->congressoList->DataTextField='Nome';
	    $this->congressoList->DataValueField='CongressoID';

        if($this->User->IsAdmin)
        {
		    $this->congressoList->DataSource=CongressoRecord::finder()->findAll();
		    $this->congressoList->dataBind();
        }
        else if($this->User->IsCp)
        {
            $criteria = new TActiveRecordCriteria;
            $criteria->Condition = "CpID = ".$this->User->Name;
		    $this->congressoList->DataSource=CongressoRecord::finder()->withCp()->findAll($criteria);
		    $this->congressoList->dataBind();
        }
    }    

    public function criarAnais($sender,$param)
	{
        if($this->IsValid)  // when all validations succeed
        {
            // populates a anaisRecord object with user inputs
            $anaisRecord                 = new AnaisRecord;
            $anaisRecord->Nome           = $this->Nome->Text; 
            $anaisRecord->Editora        = $this->Editora->Text; 
            $anaisRecord->Status         = $this->Status->Text;   
            $anaisRecord->DataPublicacao = date('Y-m-d');  
            $anaisRecord->CongressoID    = $this->congressoList->getSelectedValue();
 
            // saves to the database via Active Record mechanism
            $anaisRecord->save();
 
            // redirects the browser to the homepage
            $this->Response->redirect('./index.php?page=Anais.Listar&all=1');
        }
    }
}
?>
